package demo1;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //解码方法
    public int numDecodings(String s) {
        char[] ch = s.toCharArray();
        int n = s.length();
        int[] dp = new int[n];
        int a = 0,b = 0,sum = 0;
        if(n==1) {
            if(s.charAt(0)=='0') return 0;
            else return 1;
        }
        if(n==2){
            if(s.charAt(0)=='0') return 0;
            else {
                a = s.charAt(0) - '0';
                b = s.charAt(1) - '0';
                sum = a*10+b;
                if(sum>=1 && sum<=26) return 2;
                else return 1;
            }
        }

        return 1;
    }

    //不同路径
    public int uniquePaths(int m, int n) {
        int[][] dp = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(i==1 || j==1){
                    dp[i][j] = 1;
                }else{
                    dp[i][j] = dp[i][j-1]+dp[i-1][j];
                }
            }
        }
        return dp[m-1][n-1];
    }
}















